package com.weseal.response;

import com.weseal.exception.BaseException;

import java.io.Serializable;

/**
 * @author weseal
 * @title
 * @description
 * @usage
 * @copyright Copyright 2014  rrmj Corporation. All rights reserved.
 * @company 上海众多美网络科技有限公司
 * @create 2017/9/11
 */
public class CommonResult<T> implements Serializable {


	private static final long serialVersionUID = -4039410325904388410L;

	private String code;
	private String message;
	private T data;

	public CommonResult() {
	}

	public CommonResult(T data) {
		this.data = data;
	}

	public CommonResult(String code, String message) {
		this(code, message, null);
	}

	public CommonResult(String code, String message, T data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public static CommonResult initSuccess() {
		CommonResult responseResult = new CommonResult("200", "success");
		return responseResult;
	}

	public static CommonResult errorInstant(BaseException exception) {
		CommonResult responseResult = new CommonResult(exception.getCode(), exception.getMessage());
		return responseResult;
	}

	public static CommonResult errorInstant(Throwable expection) {
		CommonResult responseResult = new CommonResult("9999", expection.getMessage());
		return responseResult;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
}
